﻿#include <cstdio>

int main(int argc, char* argv[]) {
/*
	Format for input: input
					  in.txt
	Output will be optimal sizes for image.
*/
	if(argc != 2) {
		printf("\noptsize by {im}plicit\n\nUsage: %s in.txt\n\n\x9in.txt   - source", argv[0]);
		return 1;
	}

	FILE *fIn = fopen(argv[1], "rb");
	if(fIn == NULL) {
		printf("\nCould not open %s.", argv[1]);
		return 1;
	}

	fseek(fIn, 0, SEEK_END);
	unsigned int dwFileSize = ftell(fIn);
	fclose(fIn);

	if(dwFileSize == NULL) {
		printf("\n%s is invalid or an empty file.", argv[1]);
		return 1;
	}

	dwFileSize /= 3;

	printf("\nOptimal bmp sizes:\n");
	for(unsigned int i = 2, j = dwFileSize; i <= dwFileSize / 2; ++i) {
		for(j = dwFileSize; j >= i; --j) {
			if(i * j >= dwFileSize && i * j <= dwFileSize + dwFileSize / 30)
				printf("\n%ix%i", i, j);
		}
	}
	return 0;
}